package com.ott.Util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

import com.ott.tool.IndexForm;
 

/**
 * ͨ�ù�����
 * 
 * @author Administrator
 * 
 */
public class BaseUtil {
	/**
	 * 读取properties文件信息
	 * @param key
	 * @return
	 */	
	public static String readValue(String key) {
		if(StringUtils.isNotBlank(key)){
			//String file = BaseUtil.class.getResource("/").getPath().replaceAll("%20", " ").toString().replaceAll("file:/", "") +"configuration.properties";
			String file = IndexForm.tomcatpath+"/webapps/bestv-cinema-player/WEB-INF/classes/configuration.properties";
			Properties props = new Properties();
			try {
				InputStream in = new BufferedInputStream(new FileInputStream(file));
				props.load(in);
			 	//String value = new String(props.getProperty(key).getBytes(),"utf-8");
				String value = props.getProperty(key);
			 	return value;
			} catch (Exception e) {
		         e.printStackTrace();
		         return null;
			}
		}else{
			return null;
		}
	}
	
	/**
	 * 读取微信properties文件信息
	 * @param key
	 * @return
	 */	
	public static String readWXValue(String key) {
		if(StringUtils.isNotBlank(key)){
			String file = BaseUtil.class.getResource("/").getPath().replaceAll("%20", " ").toString().replaceAll("file:/", "") +"weixin.properties";
			Properties props = new Properties();
			try {
				InputStream in = new BufferedInputStream(new FileInputStream(file));
				props.load(in);
			 	//String value = new String(props.getProperty(key).getBytes(),"utf-8");
				String value = props.getProperty(key);
			 	return value;
			} catch (Exception e) {
		         e.printStackTrace();
		         return null;
			}
		}else{
			return null;
		}
	}
    
    public static void main(String[] args) {
    	System.out.println(readValue("ip"));
//    	System.out.println(readWXValue("ip"));
	}
}
